package com.mdc.mansion.api.web.modules.basedata;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mdc.mansion.api.web.common.web.BaseController;
import com.mdc.mansion.common.response.Result;
import com.mdc.mansion.common.response.ResultCode;
import com.mdc.mansion.common.util.SerialToolKit;
import com.mdc.mansion.core.modules.basedata.TableQrCodeService;
import com.mdc.mansion.dataaccess.modules.basedata.entity.TableQrCode;

/**<p>com.mdc.mansion.api.web.modules.basedata.TableQrCodeController</p>
 * <p>Title: TableQrCodeController</p>
 * <p>Copyright: Copyright © 2010-2014</p>
 * @version 1.0
 */
@Controller
@RequestMapping(value = "${adminPath}/qrCode")
public class TableQrCodeApiController extends BaseController {
    @Resource 
    private TableQrCodeService tableQrCodeService;
    /**
     * 创建二维码
     * @return
     */
    @RequestMapping("/create")
    public Result create(HttpServletRequest request){
        Result result = new Result(ResultCode.COMMON_SUCCESS);
        // 生成一个唯一codeSign
        String codeSign = SerialToolKit.id();
        String host = tableQrCodeService.getQrHost();
        String url = host+adminPath+ tableQrCodeService.createQrCodeUrl(codeSign);
        TableQrCode tableQrCode = new TableQrCode();
        tableQrCode.setCodeSign(codeSign);
        tableQrCode.setUrl(url);
        tableQrCodeService.save(tableQrCode);
        result.setProperty("url", url);
        result.setProperty("codeSign", codeSign);
        return result;
    }
}
